#include <stdlib.h>
#include <stdio.h>
#include "PrintStringList.h"

PrintStringList::PrintStringList()
{
	head = NULL;
	length = 0;
}
PrintStringList::PrintStringList(PrintString * headString)
{
	head = new List<PrintString>(headString, NULL);
	length = 1;
}
PrintStringList::~PrintStringList()
{
	List<PrintString> * search = head;
	while(search)
	{
		search = search->Remove();	
	}
	head = NULL;
}
char * PrintStringList::Click(Vector2D mousePosition)
{
	List<PrintString> * search = head;
	while(search)
	{
		if(search->payload)
		{
			char * str = search->payload->Click(mousePosition);
			if(str)
				return str;
		}
		search = search->next;
	}
	return NULL;
}
char * PrintStringList::GetString(int index)
{
	int count = 0;
	List<PrintString> * search = head;
	while(search)
	{
		if(count == index)
		{
			if(search->payload)
			{
				return search->payload->GetString();
			}
			return NULL;
		}
		count++;
		search = search->next;
	}
	return NULL;
}
void PrintStringList::OrderList(Vector2D topLeft, float size)
{
	List<PrintString> * search = head;
	Vector2D position = topLeft;
	while(search)
	{
		if(search->payload)
		{
			search->payload->SetPosition(position);
			search->payload->SetSize(size);
			position.y += size * 1.5;
		}
		search = search->next;
	}
}
void PrintStringList::Add(PrintString * payload)
{
	head = new List<PrintString>(payload, head);
	length++;
}
void PrintStringList::Draw()
{
	List<PrintString> * search = head;
	while(search)
	{
		if(search->payload)
			search->payload->Draw();
		search = search->next;
	}
}
void PrintStringList::Draw(Vector2D parentPosition)
{
	List<PrintString> * search = head;
	while(search)
	{
		if(search->payload)
			search->payload->Draw(parentPosition);
		search = search->next;
	}
}
void PrintStringList::Draw(Vector2D parentPosition, int startIndex, int stopIndex)
{
	List<PrintString> * search = head;
	int i = 0;
	while(search)
	{
		if(search->payload && i >= startIndex && i <= stopIndex)
			search->payload->Draw(parentPosition);
		i++;
		search = search->next;
	}
}
int PrintStringList::GetLongestStringLength()
{
	int length = 0;
	List<PrintString> * search = head;
	while(search)
	{
		if(search->payload)
			if(search->payload->GetLength() > length)
				length = search->payload->GetLength();
		search = search->next;
	}
	return length;
}
int PrintStringList::GetLength()
{
	return length;
}